package cn.xo68.boot.jwt;

import cn.xo68.core.common.Charsets;
import cn.xo68.core.crypto.EncryptConstants;
import cn.xo68.core.crypto.EncryptHandle;
import cn.xo68.core.crypto.aes.AesEncryptHandleImpl;
import cn.xo68.core.crypto.des.DesEncryptHandleImpl;
import cn.xo68.core.crypto.rsa.RsaEncryptHandleImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(JwtTokenProperties.class)
public class WxcloudJwtStarterConfiguration {


    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "wuxie.jwt",value = "enabled",havingValue = "true",matchIfMissing = true)
    JwtTokenUtil jwtTokenUtil(JwtTokenProperties jwtTokenProperties){
        EncryptHandle encryptHandle=new RsaEncryptHandleImpl(EncryptConstants.TYPE_RSA,Charsets.UTF8,512);
        return new JwtTokenUtil(jwtTokenProperties,encryptHandle);
    }

}
